﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Npgsql;

namespace posmoon.Data
{
    class DataProvider
    {
        NpgsqlConnection _conn;

        public DataProvider(NpgsqlConnection conn)
        {
            _conn = conn;
        }

        public List<string> GetDBsList()
        {
            return getDBlist();
        }

        private List<string> getDBlist()
        {
            List<string> list = new List<string>();
            
            if (_conn.State != System.Data.ConnectionState.Open)
            _conn.Open();
            
            NpgsqlCommand comm = new NpgsqlCommand("select datname from pg_database", _conn);

            try
            {
                NpgsqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    list.Add(dr[0].ToString());
                }
            }
            catch
            {

            }

            return list;
        }
    }
}
